package cn.qin.xhangapi.util.response;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 * 统一异常处理类
 *
 * @author 多仔ヾ
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * NoHandlerFoundException异常处理（404）
     *
     * @author 多仔ヾ
     * @param ex NoHandlerFoundException
     * @return cn.duozai.ct.utils.response.ResponseResult
     */
    @ExceptionHandler(NoHandlerFoundException.class)
    public ResponseResult exceptionHandler(NoHandlerFoundException ex) {
        return ResponseResult.resp(ResponseStatus.NOT_FOUND.code, ResponseStatus.NOT_FOUND.message);
    }

    /**
     * Exception异常处理（500）
     *
     * @author 多仔ヾ
     * @param ex Exception
     * @return cn.duozai.ct.utils.response.ResponseResult
     */
    @ExceptionHandler(value = Exception.class)
    public ResponseResult handler(Exception ex) {
        ex.printStackTrace();
        return ResponseResult.error();
    }

}